package br.com.ava.core.funcionario;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;

import br.com.ava.core.pessoa.PessoaFisica;

@Entity
@Table(name = "funcionario")
@PrimaryKeyJoinColumn(name = "idpessoa")
@SequenceGenerator(name = "idfuncionario_seq", sequenceName = "idfuncionario_seq", allocationSize = 1)
@SuppressWarnings({ "serial", "deprecation" })
public class Funcionario extends PessoaFisica implements UserDetails {

	private Integer idFuncionario;
	private Date dataAdmissao;
	private String senha;

	public Funcionario() {
		this.dataAdmissao = new Date();
	}

	@GeneratedValue(strategy = GenerationType.AUTO, generator = "idfuncionario_seq")
	@Column(name = "idfuncionario")
	public Integer getIdFuncionario() {
		return idFuncionario;
	}

	public void setIdFuncionario(Integer idFuncionario) {
		this.idFuncionario = idFuncionario;
	}

	@NotNull
	@Column(name = "dtadmissao", nullable = false)
	public Date getDataAdmissao() {
		return dataAdmissao;
	}

	public void setDataAdmissao(Date dataAdmissao) {
		this.dataAdmissao = dataAdmissao;
	}

	@NotNull
	@Size(max = 40)
	@Column(name = "senha", nullable = false)
	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	@Override
	@Transient
	public Collection<? extends GrantedAuthority> getAuthorities() {
		List<GrantedAuthority> retorno = new ArrayList<GrantedAuthority>();
		retorno.add(new GrantedAuthorityImpl("Funcionário"));
		return null;
	}

	@Override
	@Transient
	public String getPassword() {

		return getSenha();
	}

	@Override
	@Transient
	public String getUsername() {
		return getEmail();
	}

	@Override
	@Transient
	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	@Transient
	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	@Transient
	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	@Transient
	public boolean isEnabled() {
		// TODO Auto-generated method stub
		return false;
	}
}
